import Vue from "vue"
import Router from "vue-router"

Vue.use(Router)

import Layout from "@/layout"

export const constantRoutes = [
    {
        path: "/login",
        component: () => import("@/views/login/index"),
        hidden: true
    },

    {
        path: "/404",
        component: () => import("@/views/404"),
        hidden: true
    },

    {
        path: "/",
        component: Layout,
        redirect: "/dashboard",
        children: [
            {
                path: "dashboard",
                name: "Dashboard",
                component: () => import("@/views/dashboard/index"),
                meta: { title: "控制台", icon: "dashboard", auth: true }
            }
        ]
    },

    // 首页
    {
        path: "/home",
        component: Layout,
        redirect: "/dashboard",
        children: [
            {
                path: "",
                name: "home",
                component: () => import("@/views/home/index"),
                meta: { title: "首页标语", icon: "el-icon-s-home", auth: true }
            }
        ]
    },

    // 文章列表、文章新增、文章类型
    {
        path: "/blog",
        component: Layout,
        redirect: "/blog",
        name: "Blog",
        meta: { title: "文章管理", icon: "el-icon-notebook-2" },
        children: [
            {
                path: "/blogList",
                name: "BlogList",
                component: () => import("@/views/blogList/index.vue"),
                meta: { title: "文章列表", icon: "el-icon-files", auth: true }
            },
            {
                path: "/blogType",
                name: "BlogType",
                component: () => import("@/views/blogType/index.vue"),
                meta: { title: "文章分类", icon: "tree", auth: true }
            },
            {
                path: "/addBlog",
                name: "AddBlog",
                component: () => import("@/views/addBlog/index.vue"),
                meta: { title: "添加文章", icon: "el-icon-document-add", auth: true }
            },
            {
                path: "/editBlog/:id",
                name: "EditBlog",
                component: () => import("@/views/editBlog/index.vue"),
                meta: { title: "编辑文章", icon: "el-icon-edit-outline", auth: true },
                hidden: true
            }
        ]
    },

    // 项目管理
    {
        path: "/projects",
        component: Layout,
        redirect: "/projects",
        name: "projects",
        meta: { title: "项目管理", icon: "el-icon-suitcase" },
        children: [
            {
                path: "/projectList",
                name: "projectList",
                component: () => import("@/views/projects/index.vue"),
                meta: { title: "项目列表", icon: "el-icon-files", auth: true }
            },
            {
                path: "/addProject",
                name: "addProject",
                component: () => import("@/views/addProject/index.vue"),
                meta: { title: "添加项目", icon: "el-icon-paperclip", auth: true }
            }
        ]
    },

    // 评论管理
    {
        path: "/comment",
        component: Layout,
        children: [
            {
                path: "index",
                name: "comment",
                component: () => import("@/views/comment/index"),
                meta: { title: "评论管理", icon: "el-icon-chat-round", auth: true }
            }
        ]
    },

    // 留言板
    {
        path: "/message",
        component: Layout,
        children: [
            {
                path: "index",
                name: "Message",
                component: () => import("@/views/message/index"),
                meta: { title: "留言板", icon: "el-icon-s-order", auth: true }
            }
        ]
    },

    // 关于我页面
    {
        path: "/about",
        component: Layout,
        children: [
            {
                path: "",
                name: "about",
                component: () => import("@/views/about/index.vue"),
                meta: { title: "关于我", icon: "el-icon-s-custom", auth: true }
            }
        ]
    },

    // 设置界面
    {
        path: "/setting",
        component: Layout,
        children: [
            {
                path: "",
                name: "setting",
                component: () => import("@/views/setting/index.vue"),
                meta: { title: "设置", icon: "el-icon-setting", auth: true }
            }
        ]
    },

    // 个人设置界面
    {
        path: "/personalSetting",
        component: Layout,
        children: [
            {
                path: "",
                name: "personalSetting",
                component: () => import("@/views/personalSetting/index.vue"),
                meta: { title: "个人中心", icon: "el-icon-setting", auth: true },
                hidden: true
            }
        ]
    },

    // 404 page must be placed at the end !!!
    { path: "*", redirect: "/404", hidden: true }
]

const createRouter = () =>
    new Router({
        // mode: 'history', // require service support
        scrollBehavior: () => ({ y: 0 }),
        routes: constantRoutes,
        mode: "history"
    })

const router = createRouter()

export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
